import Vue from 'vue'
import store from './store'
import App from './App'
import http from './utils/ajax.js'
import {
	formatDateTime
} from './utils/date.js'
import clickHandle from './utils/notClickMore.js'

import uniPopup from '@/components/uni-popup/uni-popup.vue'
import uniPopupDialog from '@/components/uni-popup/uni-popup-dialog.vue'
Vue.component('uni-popup', uniPopup)
Vue.component('uni-popup-dialog', uniPopupDialog)

/**
 *  
 *  css部分使用了App.vue下的全局样式和iconfont图标，有需要图标库的可以留言。
 */
const msg = (title, duration = 1500, mask = false, icon = 'none') => {
	//统一提示方便全局修改
	if (Boolean(title) === false) {
		return
	}
	uni.showToast({
		title,
		duration,
		mask,
		icon
	})
}

const prePage = () => {
	let pages = getCurrentPages()
	let prePage = pages[pages.length - 2]
	// #ifdef H5
	return prePage
	// #endif
	return prePage.$vm
}

const formatStamp = (stamp, type) => {
	let arr = formatDateTime(stamp * 1000)
	if (type) {
		return arr[0] + '-' + arr[1] + '-' + arr[2] + ' ' + arr[3] + ':' + arr[4] + ':' + arr[5]
	} else {
		return arr[0] + '-' + arr[1] + '-' + arr[2]
	}
}

const toPage = (url, type, _this) => {
	if (type == 1) {
		if (!store.state.hasLogin) {
			_this.$refs.auth.open()
		} else {
			uni.navigateTo({
				url,
			})
		}
	} else {
		uni.navigateTo({
			url,
		})
	}
}

const pointHandle = (str, type) => {
	return str.split('.')[type]
}


Vue.config.productionTip = false
Vue.prototype.$fire = new Vue()
Vue.prototype.$store = store
Vue.prototype.$http = http
Vue.prototype.$api = {
	msg,
	prePage,
	formatStamp,
	toPage,
	pointHandle
}
Vue.prototype.$clickHandle = clickHandle

App.mpType = 'app'


const app = new Vue({
	...App
})
app.$mount()
